import {reqUserData,reqCommodities,reqPay,reqPayOther} from '@/api/index'
export default {
    namespaced:true,
    state:{
        dataOrders:[],
        goodListData:[],
        plyData:[],
    },
    getters:{},
    mutations:{
        GETADDRES(state,value){
            state.dataOrders = value
        },
        GETCOMMODITIES(state,value){
            state.goodListData = value
        },
        GETPLYAGE(state,value){
            state.plyData = value
        }
    },
    actions:{
        async getAddres({commit}){
            const reslut = await reqUserData()
            if(reslut.code == 200){
                commit('GETADDRES',reslut.data)
            }else{
                return Promise.reject('地址信息出错啦')
            }    
        },
        async getCommodities({commit}){
            const reslut = await reqCommodities()
            if(reslut.code == 200){
                commit('GETCOMMODITIES',reslut.data)
            }else{
                return Promise.reject('商品信息出错啦')
            }   
        },
        async getPlyAge({commit},data){
            const result = await reqPay(data[0],data[1])
            if(result.code == 200){
                commit('GETPLYAGE',result.data)
            }else{
                console.log(result)
                return Promise.reject('支付信息出错啦')
            }   
        },
        async getPayOther(context){
            const result = await reqPayOther(context.state.plyData)
            if(result.code == 200){
                return result.data
            }else{
                console.log('出错啦',context.state.plyData)
            }
            // context.commit('GETPAYOTHER',context.state.plyData)

        }
    }
}